package com.easy.service.impl;

import com.easy.bean.Book;
import com.easy.mapper.BookDao;
import com.easy.service.BookService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    BookDao bookDao;

    @Override
    public Book add(Book book) {
        bookDao.add(book);
        Book result = bookDao.one(book.getId());
        return result;
    }

    @Override
    public int del(Integer id) {
        return bookDao.del(id);
    }

    @Override
    public Book edit(Book book) {
        bookDao.edit(book);
        Book result = bookDao.one(book.getId());
        return result;
    }

    @Override
    public Book one(Integer id) {
        return bookDao.one(id);
    }

    @Override
    public List<Book> all(Book book) {
        return bookDao.all(book);
    }

    @Override
    public void page(Page page, Book book) {
        int count=bookDao.pageCount(book);
        Object data=bookDao.page(page,book);
        page.setCount(count);
        page.setData(data);
    }
}
